﻿Imports System
Imports System.IO
Imports System.Data.SqlServerCe
Imports System.Drawing
Imports System.Collections
Imports System.Windows.Forms
Imports System.Data
Imports System.Data.Common
Imports System.Reflection

Public Class frmEqam
    Private db As DatabaseFactory
    Private dao As EqamDao

    Private Sub frmEqam_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        db = New DatabaseFactory
        dao = New EqamDao
        'loadPdaInidata()
        loadPanel("pnlProject")
        'loadPanel("pnlCreateCoupon")
    End Sub

    Sub loadPdaInidata()        
        Dim output As String = ""
        
        Dim strAppDir As String = Path.GetDirectoryName([Assembly].GetExecutingAssembly().GetModules(0).FullyQualifiedName)
        Try
            Dim fsRead As New FileStream(strAppDir + "\eqam.DAT", FileMode.Open, FileAccess.Read)
            Dim data_reader As New StreamReader(fsRead)
            Dim line As String = data_reader.ReadLine()

            While Not line Is Nothing
                _PDA_CODE = line                
                line = data_reader.ReadLine()
            End While

            data_reader.Close()

        Catch ex As Exception
            Dim fsWrite As New FileStream(strAppDir, FileMode.Create)
            fsWrite.Close()
            MessageBox.Show("Application Init Problem", "E-QAM Init Problem")
        End Try
    End Sub

    Private Sub lvProjectList_ItemActivate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvProjectList.ItemActivate
        projectSelected()
    End Sub

    Private Sub btnProjectSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProjectSelect.Click
        projectSelected()
    End Sub

    Sub projectSelected()
        Dim sic As ListView.SelectedIndexCollection
        sic = lvProjectList.SelectedIndices()
        If sic.Count <> 0 Then
            Me.Text = lvProjectList.Items(sic.Item(0)).SubItems(0).Text
            _PROJECT_ID = lvProjectList.Items(sic.Item(0)).Tag
            _PROJECT_NAME = lvProjectList.Items(sic.Item(0)).SubItems(0).Text

            clearLoginScreen()
            loadPreviousLoginId()
            loadPanel("pnlLogin")
            loadProjectSettings()
        End If
    End Sub

    Sub loadProjectSettings()
        loadMaterialForCbo(cboWeldARMaterial)
        loadMaterialForCbo(cboCreateCouponMaterial)
        'cboWeldInputSystem
        loadSystemTypeForLv(lvCouponSystemType)

        loadHeatNoForCbo(cboWeldARHeat1, cboWeldARHeat2)
        loadHeatNoForCbo(cboWeldInputHeat1, cboWeldInputHeat2)
        loadHeatNoForCbo(cboCreateCouponHeat1, cboCreateCouponHeat2)

        'loadSystemForCbo(cboWeldInputSystem)

        loadJointTypeForCbo(cboCreateCouponJointType1, cboCreateCouponJointType2)
        loadJointTypeForCbo(cboWeldInputJointType1, cboWeldInputJointType2)
        loadJointTypeForCbo(cboWeldARJointType1, cboWeldARJointType2)

        loadSizeForCbo(_PROJECT_ID, cboWeldARSize, Nothing)        
        loadThicknessForCbo(_PROJECT_ID, cboWeldARThickness, cboCreateCouponThickness)

        loadRejectReason(cboCouponConfirmReason, cboWeldARRejectReason)

        loadZone(cboWeldingSeqZone, cboWeldingSeqZoneFilter)
    End Sub

    Sub clearLoginScreen()
        cboLoginUserName.Text = ""
        txtLoginUserPassword.Text = ""
    End Sub
    Sub loadPreviousLoginId()
        cboLoginUserName.Items.Clear()

        Dim rdr As SqlCeResultSet
        rdr = dao.findUserLog()

        While (rdr.Read)
            cboLoginUserName.Items.Add(rdr.GetString(rdr.GetOrdinal("USER_NAME")))
        End While
        dao.closeConnection()

        rdr = dao.loadPreviousLoginId()

        If (rdr.Read) Then
            cboLoginUserName.Text = rdr.GetString(rdr.GetOrdinal("USER_NAME"))
        End If

        dao.closeConnection()

        'cboLoginUserName.Text = _LAST_LOGIN_NAME
    End Sub

    Sub manipulateMenuAccessRight()
        If (_USER_ROLE = Globals.USER_ROLE_ENGINEER) Then
            Me.MenuItemAR.Enabled = True
            Me.btnAcceptReject.Enabled = True
            Me.btnAcceptReject.Visible = True
        ElseIf (_USER_ROLE = Globals.USER_ROLE_WELDER) Then
            Me.MenuItemAR.Enabled = False
            Me.btnAcceptReject.Enabled = False
            Me.btnAcceptReject.Visible = False
        End If
    End Sub

    Sub loadPanel(ByVal panelName As String)
        pnlProject.Hide()
        pnlLogin.Hide()
        pnlMenu.Hide()
        pnlCouponList.Hide()
        pnlCreateCoupon.Hide()
        pnlWeldInput.Hide()
        pnlWeldAR.Hide()
        pnlWeldReject.Hide()
        pnlEngineerCoupon.Hide()
        pnlWeldingSeq.Hide()
        pnlReplaceWeld.Hide()

        _FROM_SCREEN_ID = _SCREEN_ID
        _SCREEN_ID = panelName
        Me.menuMain.MenuItems.Remove(Me.MenuItem1)
        If (panelName = "pnlProject") Then
            pnlProject.Location = New System.Drawing.Point(_LOCATION_X, _LOCATION_Y)
            pnlProject.Size = New System.Drawing.Size(_SIZE_WIDTH, _SIZE_HEIGHT)
            pnlProject.Show()

            initProjectScreen()
        ElseIf (panelName = "pnlLogin") Then
            pnlLogin.Location = New System.Drawing.Point(_LOCATION_X, _LOCATION_Y)
            pnlLogin.Size = New System.Drawing.Size(_SIZE_WIDTH, _SIZE_HEIGHT)
            pnlLogin.Show()
        ElseIf (panelName = "pnlMenu") Then
            pnlMenu.Location = New System.Drawing.Point(_LOCATION_X, _LOCATION_Y)
            pnlMenu.Size = New System.Drawing.Size(_SIZE_WIDTH, _SIZE_HEIGHT)
            pnlMenu.Show()
            Me.menuMain.MenuItems.Add(Me.MenuItem1)

            manipulateMenuAccessRight()
        ElseIf (panelName = "pnlCouponList") Then
            pnlCouponList.Location = New System.Drawing.Point(_LOCATION_X, _LOCATION_Y)
            pnlCouponList.Size = New System.Drawing.Size(_SIZE_WIDTH, 360)
            pnlCouponList.Show()
            Me.menuMain.MenuItems.Add(Me.MenuItem1)

            If (dao.checkCouponAllOut(_PROJECT_ID, _USER_ID) = False) Then
                btnCreateCoupon.Enabled = False
            Else
                btnCreateCoupon.Enabled = True
            End If

            loadCouponScreen()
        ElseIf (panelName = "pnlEngineerCoupon") Then
            pnlEngineerCoupon.Location = New System.Drawing.Point(_LOCATION_X, _LOCATION_Y)
            pnlEngineerCoupon.Size = New System.Drawing.Size(_SIZE_WIDTH, 371)
            pnlEngineerCoupon.Show()
            Me.menuMain.MenuItems.Add(Me.MenuItem1)

            cboEngineerCouponStatus.Text = "Pending"
            loadEngineerCouponScreen()
        ElseIf (panelName = "pnlCreateCoupon") Then
            pnlCreateCoupon.Location = New System.Drawing.Point(_LOCATION_X, _LOCATION_Y)
            pnlCreateCoupon.Size = New System.Drawing.Size(_SIZE_WIDTH, 270)
            pnlCreateCoupon.Show()
            Me.menuMain.MenuItems.Add(Me.MenuItem1)

            '''''''''''''''  Load Create Coupon Screen ''''''''''''''''''''''''''''''''''''
            'loadMaterialForCbo(cboCreateCouponMaterial)
            'loadHeatForCbo(cboCreateCouponHeat1, cboCreateCouponHeat2)
            'loadSystemTypeForLv(lvCouponSystemType)            
            btnSaveCoupon.Text = "Save"
            txtCreateCouponNo.Text = ""
            txtCreateCouponBarcode.Text = ""
            cboCreateCouponSize.DropDownStyle = ComboBoxStyle.DropDownList

            Me.tabCreateCoupon.SelectedIndex = 0
            Me.tabCreateCoupon.Refresh()

            'loadSystemForCbo()
            'cboCreateCouponCoax.Text = ""
            'cboCreateCouponMaterial.Text = ""
            'cboCreateCouponSize.Text = ""
            'cboCreateCouponThickness.Text = ""
        ElseIf (panelName = "pnlWeldInput") Then
            pnlWeldInput.Location = New System.Drawing.Point(_LOCATION_X, _LOCATION_Y)
            pnlWeldInput.Size = New System.Drawing.Size(_SIZE_WIDTH, 317)
            pnlWeldInput.Show()
            Me.menuMain.MenuItems.Add(Me.MenuItem1)

            loadCouponSystemForCbo(cboWeldInputSystem, _COUPON_ID)
            '''' init screen
            'loadSystemForCbo(cboWeldInputSystem)
            'loadHeadNoForCbo(cboWeldInputHeatNumber)
            'loadJointTypeForCbo(cboWeldInputJointType1)
            'loadJointTypeForCbo(cboWeldInputJointType2)
        ElseIf (panelName = "pnlWeldAR") Then
            pnlWeldAR.Location = New System.Drawing.Point(_LOCATION_X, _LOCATION_Y)
            pnlWeldAR.Size = New System.Drawing.Size(_SIZE_WIDTH, 393)
            pnlWeldAR.Show()
            Me.menuMain.MenuItems.Add(Me.MenuItem1)

            clearPnlWeldAR()
            loadCouponSystemForCbo(cboWeldARSystem, _COUPON_ID)
        ElseIf (panelName = "pnlWeldReject") Then
            pnlWeldReject.Location = New System.Drawing.Point(_LOCATION_X, _LOCATION_Y)
            pnlWeldReject.Size = New System.Drawing.Size(_SIZE_WIDTH, 276)
            pnlWeldReject.Show()
            Me.menuMain.MenuItems.Add(Me.MenuItem1)
        ElseIf (panelName = "pnlWeldingSeq") Then
            pnlWeldingSeq.Location = New System.Drawing.Point(_LOCATION_X, _LOCATION_Y)
            pnlWeldingSeq.Size = New System.Drawing.Size(_SIZE_WIDTH, 310)
            pnlWeldingSeq.Show()
            Me.menuMain.MenuItems.Add(Me.MenuItem1)
        ElseIf (panelName = "pnlReplaceWeld") Then
            pnlReplaceWeld.Location = New System.Drawing.Point(_LOCATION_X, _LOCATION_Y)
            pnlReplaceWeld.Size = New System.Drawing.Size(_SIZE_WIDTH, 349)
            pnlReplaceWeld.Show()
            Me.menuMain.MenuItems.Add(Me.MenuItem1)
        End If
    End Sub

    Sub initProjectScreen()
        Dim rdr As SqlCeResultSet
        Dim lstViewCust As New ListViewItem

        Try
            rdr = dao.findEqamProjects(Nothing, "A")
            lvProjectList.Items.Clear()

            While (rdr.Read)
                lstViewCust = Me.lvProjectList.Items.Add(New ListViewItem(rdr.GetString(rdr.GetOrdinal("PROJECT_NAME"))))
                Dim statusCode As String = ""
                If (rdr.GetString(rdr.GetOrdinal("STATUS_CODE")) = "A") Then
                    statusCode = "ACTIVE"
                Else
                    statusCode = "IN-ACTIVE"
                End If
                lstViewCust.SubItems.Add(statusCode)
                lstViewCust.Tag = rdr.GetString(rdr.GetOrdinal("PROJECT_ID"))
            End While
            dao.closeConnection()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub refreshComboCouponCreateDate(ByVal cbo As System.Windows.Forms.ComboBox)
        cbo.Items.Clear()

        Dim rdr As SqlCeResultSet
        rdr = dao.findCouponCreateDateByGroup()

        While (rdr.Read)
            cbo.Items.Add(rdr.GetDecimal(rdr.GetOrdinal("DATE_ADD")))
        End While
        dao.closeConnection()
    End Sub

    Private Sub refreshComboCouponNo(ByVal cbo As System.Windows.Forms.ComboBox)
        cbo.Items.Clear()

        Dim rdr As SqlCeResultSet
        rdr = dao.findCouponNoByGroup()

        While (rdr.Read)
            cbo.Items.Add(rdr.GetString(rdr.GetOrdinal("COUPON_CODE")))
        End While
        dao.closeConnection()
    End Sub

    Private Sub loadEngineerCouponScreen()
        pnlCouponConfirm.Visible = False
        refreshComboCouponCreateDate(cboEngineerCouponDate)
        refreshComboCouponNo(cboEngineerCouponNo)

        Dim status As String = ""
        If (cboEngineerCouponStatus.Text = "Pending") Then
            status = Globals.COUPON_STATUS_PENDING
        ElseIf (cboEngineerCouponStatus.Text = "Approve") Then
            status = Globals.COUPON_STATUS_APPROVED
        ElseIf (cboEngineerCouponStatus.Text = "Reject") Then
            status = Globals.COUPON_STATUS_REJECTED
        ElseIf (cboEngineerCouponStatus.Text = "Complete") Then
            status = Globals.COUPON_STATUS_COMPLETED
        End If
        searchCoupon(cboEngineerCouponDate.Text, cboEngineerCouponNo.Text, status, txtEngineerCouponBarcode.Text, cboEngineerCouponIO.Text, lvEngineerCouponList)

        engineerCouponScreen_default()
    End Sub

    Sub searchCoupon(ByVal couponDate As String, ByVal couponNo As String, ByVal status As String, ByVal barcode As String, ByVal couponInOut As String, ByVal lv As System.Windows.Forms.ListView)
        Dim rdr As SqlCeResultSet        
        Dim lstView As New ListViewItem

        rdr = dao.findEqamEngineerCouponLists(_PROJECT_ID, couponDate, couponNo, status, vbNullString, barcode, couponInOut)

        lv.Items.Clear()
        While (rdr.Read)
            lstView = lv.Items.Add(New ListViewItem(rdr.GetString(rdr.GetOrdinal("COUPON_CODE")) & "-" & rdr.GetString(rdr.GetOrdinal("COUPON_TYPE"))))
            lstView.SubItems.Add(rdr.GetString(rdr.GetOrdinal("USER_NAME")))
            lstView.SubItems.Add(rdr.GetString(rdr.GetOrdinal("MATERIAL")) & "-" & rdr.GetString(rdr.GetOrdinal("SIZE")) & "-" & rdr.GetString(rdr.GetOrdinal("THICKNESS")))
            lstView.SubItems.Add(rdr.GetString(rdr.GetOrdinal("STATUS_CODE")))
            lstView.SubItems.Add(rdr.GetDecimal(rdr.GetOrdinal("DATE_ADD")) & "-" & rdr.GetDecimal(rdr.GetOrdinal("TIME_ADD")))

            If (rdr.IsDBNull(rdr.GetOrdinal("WELD_COUNT"))) Then
                lstView.SubItems.Add(0)
            Else
                lstView.SubItems.Add(rdr.GetInt32(rdr.GetOrdinal("WELD_COUNT")))
            End If


            '''''''''''''''''''''''''''''''
            Dim rdrSystem As SqlCeResultSet
            Dim systemString As String = ""
            rdrSystem = dao.findCouponSystems(couponNo)

            While (rdrSystem.Read)
                If (systemString <> "") Then
                    systemString &= ","
                End If

                systemString &= rdrSystem.GetString(rdrSystem.GetOrdinal("SYSTEM_TYPE_NAME"))
            End While
            ''''''''''''''''''''''''''''''
            lstView.SubItems.Add(systemString)
            lstView.SubItems.Add(rdr.GetString(rdr.GetOrdinal("COAX")))

            If (rdr.IsDBNull(rdr.GetOrdinal("REMARKS"))) Then
                lstView.SubItems.Add("")
            Else
                lstView.SubItems.Add(rdr.GetString(rdr.GetOrdinal("REMARKS")))
            End If

            lstView.Tag = rdr.GetInt64(rdr.GetOrdinal("COUPON_ID"))
        End While
        dao.closeConnection()
    End Sub

    Sub engineerCouponScreen_default()
        btnEngineerCouponApprove.Enabled = False
        btnEngineerCouponEdit.Enabled = False
    End Sub

    Private Sub loadCouponScreen()
        Dim rdr As SqlCeResultSet
        Dim lstView As New ListViewItem

        rdr = dao.findEqamProjects(_PROJECT_ID, Nothing)

        If (rdr.Read) Then
            txtCouponProjectName.Text = rdr.GetString(rdr.GetOrdinal("PROJECT_NAME"))
            txtCouponSupervisor.Text = rdr.GetString(rdr.GetOrdinal("SUPERVISOR_NAME"))

            If (USER_ROLE_WELDER = _USER_ROLE) Then
                txtCouponWelder.Text = _USER_NAME
            Else
                txtCouponWelder.Text = ""
            End If
        End If

        cboCouponStatus.Text = "Approve"
        welderFindCoupon()

        'rdr2 = dao.findEqamCoupons(_USER_ID, Globals.COUPON_TYPE_IN)

        'Me.lvCoupon.Items.Clear()
        'While (rdr2.Read)
        'lstView = Me.lvCoupon.Items.Add(New ListViewItem(rdr2.GetString(rdr2.GetOrdinal("COUPON_CODE"))))
        'lstView.SubItems.Add(rdr2.GetString(rdr2.GetOrdinal("MATERIAL")) & "-" & rdr2.GetString(rdr2.GetOrdinal("SIZE")) & "-" & rdr2.GetString(rdr2.GetOrdinal("THICKNESS")))
        'lstView.SubItems.Add(rdr2.GetString(rdr2.GetOrdinal("STATUS_CODE")))
        'lstView.Tag = rdr2.GetInt64(rdr2.GetOrdinal("COUPON_ID"))
        'End While

        'dao.closeConnection()

        refreshComboCouponNo(cboCouponNo)
        refreshComboCouponCreateDate(cboCouponDate)

        btnStartCoupon_default()
    End Sub

    Private Sub btnMenuCoupon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMenuCoupon.Click
        If (Globals.USER_ROLE_WELDER = _USER_ROLE) Then
            loadPanel("pnlCouponList")
        ElseIf (Globals.USER_ROLE_ENGINEER = _USER_ROLE) Then
            loadPanel("pnlEngineerCoupon")
        End If
    End Sub

    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        Dim rdr As SqlCeResultSet

        rdr = dao.findUsers(cboLoginUserName.Text, txtLoginUserPassword.Text)

        Me.lvProjectList.Items.Clear()
        If (rdr.Read) Then
            _LAST_LOGIN_NAME = cboLoginUserName.Text
            _USER_ID = rdr.GetString(rdr.GetOrdinal("USER_ID"))
            _USER_NAME = rdr.GetString(rdr.GetOrdinal("USER_NAME"))
            _USER_ROLE = rdr.GetString(rdr.GetOrdinal("USER_ROLE"))

            If (Globals.USER_ROLE_WELDER = _USER_ROLE) Then
                loadPanel("pnlMenu")
                loadWeldSizeForCbo(_USER_ID, cboCreateCouponSize)
                notifyRejectedWeld()
            ElseIf (Globals.USER_ROLE_ENGINEER = _USER_ROLE) Then
                loadPanel("pnlMenu")
            End If

            dao.doCreateLogInLog(_USER_NAME)
        Else
            MsgBox("Invalid Username and Password", MsgBoxStyle.Exclamation, "Error")
        End If
        dao.closeConnection()
    End Sub


    Private Sub notifyRejectedWeld()
        Dim rdr As SqlCeResultSet
        rdr = dao.findWeldLogs(Nothing, Nothing, Nothing, WELDLOG_STATUS_REJECTED, Nothing, Globals.COUPON_TYPE_IN, True, _USER_ID)

        Dim rejectedWeldCount As Integer = 0
        While (rdr.Read)
            rejectedWeldCount = rejectedWeldCount + 1
        End While

        If (rejectedWeldCount <> 0) Then
            MsgBox(rejectedWeldCount & " welds pending to replace.", MsgBoxStyle.Information, "EQAM findWeldLogs")
        End If
    End Sub

    Private Sub MenuItemCoupon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemCoupon.Click
        If (Globals.USER_ROLE_WELDER = _USER_ROLE) Then
            loadPanel("pnlCouponList")
        ElseIf (Globals.USER_ROLE_ENGINEER = _USER_ROLE) Then
            loadPanel("pnlEngineerCoupon")
        End If
    End Sub

    Private Sub MenuItemAR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemAR.Click
        loadPanel("pnlWeldAR")
    End Sub

    Private Sub MenuItemLogOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemLogOut.Click
        loadPanel("pnlProject")
    End Sub

    Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
        loadPanel("pnlMenu")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Label1_ParentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Function loadMaterialForCbo(ByVal cbo As System.Windows.Forms.ComboBox) As System.Windows.Forms.ComboBox
        cbo.Items.Clear()

        Dim rdr As SqlCeResultSet
        rdr = dao.findMaterials()

        While (rdr.Read)
            cbo.Items.Add(rdr.GetString(rdr.GetOrdinal("MATERIAL")))
        End While
        dao.closeConnection()

        Return cbo
    End Function

    Private Function loadRejectReason(ByVal cbo As System.Windows.Forms.ComboBox, ByVal cbo2 As System.Windows.Forms.ComboBox) As System.Windows.Forms.ComboBox
        cbo.Items.Clear()
        If (cbo2 IsNot Nothing) Then
            cbo2.Items.Clear()
        End If

        Dim rdr As SqlCeResultSet
        rdr = dao.findRejectReason()

        While (rdr.Read)
            cbo.Items.Add(rdr.GetString(rdr.GetOrdinal("REASON")))
            If (cbo2 IsNot Nothing) Then
                cbo2.Items.Add(rdr.GetString(rdr.GetOrdinal("REASON")))
            End If
        End While
        dao.closeConnection()

        Return cbo
    End Function

    Private Function loadCouponSystemForCbo(ByVal cbo As System.Windows.Forms.ComboBox, ByVal couponId As String) As System.Windows.Forms.ComboBox
        cbo.Items.Clear()

        Dim rdr As SqlCeResultSet
        rdr = dao.findCouponSystems(couponId)

        While (rdr.Read)
            cbo.Items.Add(rdr.GetString(rdr.GetOrdinal("SYSTEM_TYPE_NAME")))

        End While
        dao.closeConnection()

        Return cbo
    End Function

    Private Function loadZone(ByVal cbo As System.Windows.Forms.ComboBox, ByVal cbo2 As System.Windows.Forms.ComboBox) As System.Windows.Forms.ComboBox
        cbo.Items.Clear()
        If (cbo2 IsNot Nothing) Then
            cbo2.Items.Clear()
        End If

        Dim rdr As SqlCeResultSet
        rdr = dao.findZones(Nothing, _PROJECT_ID)

        While (rdr.Read)
            cbo.Items.Add(rdr.GetString(rdr.GetOrdinal("ZONE")))

            If (cbo2 IsNot Nothing) Then
                cbo2.Items.Add(rdr.GetString(rdr.GetOrdinal("ZONE")))
            End If
        End While
        dao.closeConnection()

        Return cbo
    End Function

    Private Function loadHeatNoForCbo(ByVal cbo As System.Windows.Forms.ComboBox, ByVal cbo2 As System.Windows.Forms.ComboBox) As System.Windows.Forms.ComboBox
        cbo.Items.Clear()
        If (cbo2 IsNot Nothing) Then
            cbo2.Items.Clear()
        End If

        Dim rdr As SqlCeResultSet
        rdr = dao.findHeatNos(_PROJECT_ID, Nothing)

        While (rdr.Read)
            cbo.Items.Add(rdr.GetString(rdr.GetOrdinal("HEAT_NUMBER_NAME")))

            If (cbo2 IsNot Nothing) Then
                cbo2.Items.Add(rdr.GetString(rdr.GetOrdinal("HEAT_NUMBER_NAME")))
            End If
        End While
        dao.closeConnection()

        Return cbo
    End Function

    Private Function loadSystemTypeForLv(ByVal lv As System.Windows.Forms.ListView) As System.Windows.Forms.ListView
        Dim rdr As SqlCeResultSet
        Dim lstViewCust As New ListViewItem

        Try
            rdr = dao.findSystemTypes(_PROJECT_ID, Nothing)
            lv.Items.Clear()

            While (rdr.Read)
                lstViewCust = lv.Items.Add(New ListViewItem(rdr.GetString(rdr.GetOrdinal("SYSTEM_TYPE_NAME"))))
                'lstViewCust.SubItems.Add(rdr.GetString(rdr.GetOrdinal("STATUS_CODE")))
                lstViewCust.Tag = rdr.GetString(rdr.GetOrdinal("SYSTEM_TYPE_ID"))
            End While
            dao.closeConnection()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "EQAM")
        End Try
        Return lv
    End Function

    Private Function loadSystemForCbo(ByVal cbo As System.Windows.Forms.ComboBox) As System.Windows.Forms.ComboBox
        cbo.Items.Clear()

        Dim rdr As SqlCeResultSet
        rdr = dao.findSystemTypes(_PROJECT_ID, Nothing)

        While (rdr.Read)
            cbo.Items.Add(rdr.GetString(rdr.GetOrdinal("SYSTEM_TYPE_NAME")))
        End While
        dao.closeConnection()

        Return cbo
    End Function

    Private Function loadSizeForCbo(ByVal projectId As String, ByVal cbo As System.Windows.Forms.ComboBox, ByVal cbo2 As System.Windows.Forms.ComboBox) As System.Windows.Forms.ComboBox
        cbo.Items.Clear()
        If (cbo2 IsNot Nothing) Then
            cbo2.Items.Clear()
        End If

        Dim rdr As SqlCeResultSet
        rdr = dao.findGroupBySizes(projectId)

        While (rdr.Read)
            cbo.Items.Add(rdr.GetString(rdr.GetOrdinal("SIZE")))
            If (cbo2 IsNot Nothing) Then
                cbo2.Items.Add(rdr.GetString(rdr.GetOrdinal("SIZE")))
            End If
        End While
        dao.closeConnection()

        Return cbo
    End Function

    Private Function loadWeldSizeForCbo(ByVal welderId As String, ByVal cbo As System.Windows.Forms.ComboBox) As System.Windows.Forms.ComboBox
        cbo.Items.Clear()

        Dim rdr As SqlCeResultSet
        rdr = dao.findWeldSize(welderId)

        While (rdr.Read)
            cbo.Items.Add(rdr.GetString(rdr.GetOrdinal("SIZE")))
        End While
        dao.closeConnection()

        Return cbo
    End Function

    Private Function loadThicknessForCbo(ByVal projectId As String, ByVal cbo As System.Windows.Forms.ComboBox, ByVal cbo2 As System.Windows.Forms.ComboBox) As System.Windows.Forms.ComboBox
        cbo.Items.Clear()
        If (cbo2 IsNot Nothing) Then
            cbo2.Items.Clear()
        End If

        Dim rdr As SqlCeResultSet
        rdr = dao.findGroupByThickness(projectId)

        While (rdr.Read)
            cbo.Items.Add(rdr.GetString(rdr.GetOrdinal("THICKNESS")))
            If (cbo2 IsNot Nothing) Then
                cbo2.Items.Add(rdr.GetString(rdr.GetOrdinal("THICKNESS")))
            End If
        End While
        dao.closeConnection()

        Return cbo
    End Function

    Private Function loadJointTypeForCbo(ByVal cbo As System.Windows.Forms.ComboBox, ByVal cbo2 As System.Windows.Forms.ComboBox) As System.Windows.Forms.ComboBox
        cbo.Items.Clear()
        If (cbo2 IsNot Nothing) Then
            cbo2.Items.Clear()
        End If

        Dim rdr As SqlCeResultSet
        rdr = dao.findJointTypes(Nothing)

        While (rdr.Read)
            cbo.Items.Add(rdr.GetString(rdr.GetOrdinal("JOINT_TYPE_NAME")))
            If (cbo2 IsNot Nothing) Then
                cbo2.Items.Add(rdr.GetString(rdr.GetOrdinal("JOINT_TYPE_NAME")))
            End If
        End While
        dao.closeConnection()

        Return cbo
    End Function

    Private Sub btnCreateCoupon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateCoupon.Click
        loadPanel("pnlCreateCoupon")
    End Sub

    Private Sub btnStartCoupon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartCoupon.Click
        Dim sic As ListView.SelectedIndexCollection
        sic = lvCoupon.SelectedIndices()

        If sic.Count <> 0 Then
            _ACTION_ID = lvCoupon.Items(sic.Item(0)).Tag

            If btnStartCoupon.Text = Globals.BUTTON_LABEL_REDO Then
                _ACTION = Globals.BUTTON_LABEL_REDO
                editCoupon(_ACTION_ID)
            ElseIf btnStartCoupon.Text = Globals.BUTTON_LABEL_EDIT Then
                _ACTION = Globals.BUTTON_LABEL_EDIT
                editCoupon(_ACTION_ID)
            ElseIf btnStartCoupon.Text = Globals.BUTTON_LABEL_START Then
                _ACTION = Globals.BUTTON_LABEL_START
                btnWeldConfirm.Text = Globals.BUTTON_LABEL_CONFIRM
                startCouponInput(_ACTION_ID)
            End If
        End If
    End Sub

    Private Sub btnCancelCoupon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelCoupon.Click
        loadPanel(_FROM_SCREEN_ID)
    End Sub

    Private Sub btnSaveCoupon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveCoupon.Click
        ' save coupon        
        Dim returnExecute As Boolean = False

        If (txtCreateCouponBarcode.Text <> "" And dao.checkBarcodeDuplication(txtCreateCouponBarcode.Text)) Then
            MsgBox(txtCreateCouponBarcode.Text & " alraedy exists.", MsgBoxStyle.Information, "EQAM")
            Me.tabCreateCoupon.SelectedIndex = 0
            Me.tabCreateCoupon.Refresh()
            Return
        End If

        Dim pipeTube As String = ""
        Dim isCoax As String = "F"


        Dim lstItem As ListViewItem
        Dim itemChecked As Boolean = False
        For Each lstItem In lvCouponSystemType.Items
            If (lstItem.Checked) Then
                itemChecked = True
                Exit For
            End If
        Next

        If (txtCreateCouponBarcode.Text = "") Then
            MsgBox("Barcode cannot be blank.", MsgBoxStyle.Information, "Error")
            Me.tabCreateCoupon.SelectedIndex = 0
            Me.tabCreateCoupon.Refresh()
            Return
        End If

        If (cboCreateCouponMaterial.Text = "") Then
            MsgBox("Material cannot be blank.", MsgBoxStyle.Information, "Error")
            Me.tabCreateCoupon.SelectedIndex = 0
            Me.tabCreateCoupon.Refresh()
            Return
        End If

        If (cboCreateCouponSize.Text = "") Then
            MsgBox("Size cannot be blank.", MsgBoxStyle.Information, "Error")
            Me.tabCreateCoupon.SelectedIndex = 0
            Me.tabCreateCoupon.Refresh()
            Return
        End If

        If (cboCreateCouponThickness.Text = "") Then
            MsgBox("Thickness cannot be blank.", MsgBoxStyle.Information, "Error")
            Me.tabCreateCoupon.SelectedIndex = 0
            Me.tabCreateCoupon.Refresh()
            Return
        End If

        If (cboCreateCouponJointType1.Text = "" Or cboCreateCouponJointType2.Text = "") Then
            MsgBox("Joint Type cannot be blank.", MsgBoxStyle.Information, "Error")
            Me.tabCreateCoupon.SelectedIndex = 0
            Me.tabCreateCoupon.Refresh()
            Return
        End If

        If (cboCreateCouponHeat1.Text = "" Or cboCreateCouponHeat2.Text = "") Then
            MsgBox("Heat Number cannot be blank.", MsgBoxStyle.Information, "Error")
            Me.tabCreateCoupon.SelectedIndex = 0
            Me.tabCreateCoupon.Refresh()
            Return
        End If

        If (itemChecked = False) Then
            MsgBox("System Type have to check at least one.", MsgBoxStyle.Information, "Error")
            Me.tabCreateCoupon.SelectedIndex = 1
            Me.tabCreateCoupon.Refresh()
            Return
        End If

        Dim coax As String = ""
        If chkCreateCouponCoax.Checked = True Then
            isCoax = "T"
            coax = cboCreateCouponCoax.Text
        End If

        If rdoCreateCouponPipe.Checked = True Then
            pipeTube = "PIPE"
        ElseIf rdoCreateCouponTube.Checked = True Then
            pipeTube = "TUBE"
        End If

        Dim heatId1 As String = ""
        Dim heatName1 As String = cboCreateCouponHeat1.Text
        Dim heatId2 As String = ""
        Dim heatName2 As String = cboCreateCouponHeat2.Text
        Dim rdr As SqlCeResultSet
        rdr = dao.findHeatNos(Nothing, cboCreateCouponHeat1.Text)
        If (rdr.Read) Then
            heatId1 = rdr.GetString(rdr.GetOrdinal("HEAT_NUMBER_ID"))
        End If
        dao.closeConnection()
        rdr = dao.findHeatNos(Nothing, cboCreateCouponHeat2.Text)
        If (rdr.Read) Then
            heatId2 = rdr.GetString(rdr.GetOrdinal("HEAT_NUMBER_ID"))
        End If
        dao.closeConnection()

        Dim jointTypeCode1 As String = ""
        Dim jointTypeName1 As String = cboCreateCouponJointType1.Text
        Dim jointTypeCode2 As String = ""
        Dim jointTypeName2 As String = cboCreateCouponJointType2.Text
        rdr = dao.findJointTypes(cboWeldInputJointType1.Text)
        If (rdr.Read) Then
            jointTypeCode1 = rdr.GetString(rdr.GetOrdinal("JOINT_TYPE_CODE"))
        End If
        dao.closeConnection()
        rdr = dao.findJointTypes(cboWeldInputJointType2.Text)
        If (rdr.Read) Then
            jointTypeCode2 = rdr.GetString(rdr.GetOrdinal("JOINT_TYPE_CODE"))
        End If
        dao.closeConnection()

        If btnSaveCoupon.Text = Globals.BUTTON_LABEL_SAVE Then
            returnExecute = dao.doCreateCoupon(_USER_ID, coax, _PROJECT_ID, cboCreateCouponMaterial.Text, cboCreateCouponSize.Text, cboCreateCouponThickness.Text, isCoax, pipeTube, Globals.COUPON_TYPE_IN, heatId1, heatName1, heatId2, heatName2, lvCouponSystemType, "0", txtCreateCouponBarcode.Text, jointTypeCode1, jointTypeName1, jointTypeCode2, jointTypeName2)
        ElseIf btnSaveCoupon.Text = Globals.BUTTON_LABEL_REDO Then
            returnExecute = dao.doCreateCoupon(_USER_ID, coax, _PROJECT_ID, cboCreateCouponMaterial.Text, cboCreateCouponSize.Text, cboCreateCouponThickness.Text, isCoax, pipeTube, Globals.COUPON_TYPE_IN, heatId1, heatName1, heatId2, heatName2, lvCouponSystemType, _COUPON_ID, txtCreateCouponBarcode.Text, jointTypeCode1, jointTypeName1, jointTypeCode2, jointTypeName2)
        ElseIf btnSaveCoupon.Text = Globals.BUTTON_LABEL_UPDATE Then
            returnExecute = dao.doUpdateCoupon(_USER_ID, _COUPON_ID, coax, cboCreateCouponMaterial.Text, cboCreateCouponSize.Text, cboCreateCouponThickness.Text, isCoax, pipeTube, heatId1, heatName1, heatId2, heatName2, lvCouponSystemType, txtCreateCouponBarcode.Text, jointTypeCode1, jointTypeName1, jointTypeCode2, jointTypeName2)
        End If

        If returnExecute = True Then
            MsgBox(_SAVE_SUCCESSFUL_MESSAGE, MsgBoxStyle.Information, "EQAM")            
            loadPanel(_FROM_SCREEN_ID)
        Else
            'MessageBox.Show("Error!")
            Return
        End If
    End Sub

    Private Sub btnWeldConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWeldConfirm.Click
        Dim returnExecute As Boolean = False
        Dim pipeTube As String = lblWeldInputPT.Text
        Dim isCoax As String = lblWeldInputIsCoax.Text
        Dim coax As String = lblWeldInputCoax.Text
        Dim heatId1 As String = ""
        Dim heatName1 As String = cboWeldInputHeat1.Text
        Dim heatId2 As String = ""
        Dim heatName2 As String = cboWeldInputHeat2.Text
        Dim rdr As SqlCeResultSet

        If (isCoax = "T") Then
        Else
            If (txtWeldInputBarcodeI.Text <> "" And dao.checkBarcodeDuplication(txtWeldInputBarcodeI.Text)) Then
                MsgBox(txtWeldInputBarcodeI.Text & " (I) alraedy exists.", MsgBoxStyle.Information, "EQAM")
                Return
            End If
        End If
        
        If (txtWeldInputBarcodeO1.Text <> "" And dao.checkBarcodeDuplication(txtWeldInputBarcodeO1.Text)) Then
            MsgBox(txtWeldInputBarcodeO1.Text & " (O) alraedy exists.", MsgBoxStyle.Information, "EQAM")
            Return
        End If
        If (txtWeldInputBarcodeO2.Text <> "" And dao.checkBarcodeDuplication(txtWeldInputBarcodeO2.Text)) Then
            MsgBox(txtWeldInputBarcodeO2.Text & " (O) alraedy exists.", MsgBoxStyle.Information, "EQAM")
            Return
        End If

        rdr = dao.findHeatNos(Nothing, cboWeldInputHeat1.Text)
        If (rdr.Read) Then
            heatId1 = rdr.GetString(rdr.GetOrdinal("HEAT_NUMBER_ID"))
        End If
        dao.closeConnection()
        rdr = dao.findHeatNos(Nothing, cboWeldInputHeat2.Text)
        If (rdr.Read) Then
            heatId2 = rdr.GetString(rdr.GetOrdinal("HEAT_NUMBER_ID"))
        End If
        dao.closeConnection()

        Dim jointTypeCode1 As String = ""
        Dim jointTypeName1 As String = cboWeldInputJointType1.Text
        Dim jointTypeCode2 As String = ""
        Dim jointTypeName2 As String = cboWeldInputJointType2.Text
        rdr = dao.findJointTypes(cboWeldInputJointType1.Text)
        If (rdr.Read) Then
            jointTypeCode1 = rdr.GetString(rdr.GetOrdinal("JOINT_TYPE_CODE"))
        End If
        dao.closeConnection()
        rdr = dao.findJointTypes(cboWeldInputJointType2.Text)
        If (rdr.Read) Then
            jointTypeCode2 = rdr.GetString(rdr.GetOrdinal("JOINT_TYPE_CODE"))
        End If
        dao.closeConnection()

        Dim systemId As String = ""
        Dim systemName As String = cboWeldInputSystem.Text
        rdr = dao.findSystemTypes(Nothing, cboWeldInputSystem.Text)
        If (rdr.Read) Then
            systemId = rdr.GetString(rdr.GetOrdinal("SYSTEM_TYPE_ID"))
        End If
        dao.closeConnection()

        Dim seq As Integer = Nothing
        If (txtWeldInputSeq.Text <> "") Then
            Try
                seq = Convert.ToDecimal(txtWeldInputSeq.Text)
            Catch ex As Exception
                'seq
            End Try
        End If

        If btnWeldConfirm.Text = Globals.BUTTON_LABEL_CONFIRM Then
            If (chkWeldInputCouponOut.Checked = True) Then
                'If (txtWeldInputBarcode.Text = "") Then
                'MsgBox("Barcode cannot be blank.", MsgBoxStyle.Exclamation, "E-QAM")
                'txtWeldInputBarcode.Focus()
                'Return
                'End If

                'returnExecute = dao.doCouponOut(_USER_ID, txtWeldInputBarcodeO1.Text, txtWeldInputBarcodeO2.Text, txtWeldInputBarcodeI.Text, systemId, systemName, heatId1, heatName1, heatId2, heatName2, jointTypeCode1, jointTypeName1, jointTypeCode2, jointTypeName2)
                returnExecute = dao.doCreateCoupon(_USER_ID, coax, _PROJECT_ID, lblWeldInputMaterial.Text, lblWeldInputSize.Text, lblWeldInputThickness.Text, isCoax, pipeTube, Globals.COUPON_TYPE_OUT, heatId1, heatName1, heatId2, heatName2, Nothing, "0", txtWeldInputBarcodeI.Text, jointTypeCode1, jointTypeName1, jointTypeCode2, jointTypeName2)
                If returnExecute = True Then
                    MsgBox("Coupon Out Successfully.", MsgBoxStyle.Information, "EQAM")
                    loadPanel("pnlCouponList")
                Else
                    'MessageBox.Show("Error!")
                    Return
                End If
            Else
                If (txtWeldInputBarcodeI.Text = "") Then
                    If (isCoax = "T") Then
                        MsgBox("Barcode (I) cannot be blank.", MsgBoxStyle.Exclamation, "E-QAM")
                    Else
                        MsgBox("Barcode cannot be blank.", MsgBoxStyle.Exclamation, "E-QAM")
                    End If

                    txtWeldInputBarcodeI.Focus()
                    Return
                End If

                If (isCoax = "T" And coax = "Outer" And chkWeldInputCouponOut.Checked = False) Then
                    If (txtWeldInputBarcodeO1.Text = "") Then
                        MsgBox("Barcode (O) cannot be blank.", MsgBoxStyle.Exclamation, "E-QAM")
                        txtWeldInputBarcodeO1.Focus()
                        Return
                    End If

                    If (txtWeldInputBarcodeO2.Text = "") Then
                        MsgBox("Barcode (O) cannot be blank.", MsgBoxStyle.Exclamation, "E-QAM")
                        txtWeldInputBarcodeO2.Focus()
                        Return
                    End If
                End If

                If (seq = Nothing) Then
                    seq = dao.getWeldLogDetailMaxSeq(_COUPON_CODE)
                End If

                returnExecute = dao.doCreateWeldLog(_USER_ID, txtWeldInputBarcodeO1.Text, txtWeldInputBarcodeO2.Text, txtWeldInputBarcodeI.Text, systemId, systemName, heatId1, heatName1, heatId2, heatName2, jointTypeCode1, jointTypeName1, jointTypeCode2, jointTypeName2, seq)
                If returnExecute = True Then
                    If MsgBox("Click YES for next scan", MsgBoxStyle.YesNo, "E-QAM") = vbYes Then
                        txtWeldInputBarcodeO1.Text = ""
                        txtWeldInputBarcodeO2.Text = ""
                        txtWeldInputBarcodeI.Text = ""
                        txtWeldInputBarcodeI.Focus()
                    Else
                        loadPanel("pnlCouponList")
                    End If
                Else
                    'MessageBox.Show("Error!")
                    Return
                End If
            End If
        ElseIf btnWeldConfirm.Text = Globals.BUTTON_LABEL_UPDATE Then
            returnExecute = dao.updateWeldLog(_USER_ID, txtWeldInputBarcodeO1.Text, txtWeldInputBarcodeO2.Text, txtWeldInputBarcodeI.Text, systemId, systemName, heatId1, heatName1, heatId2, heatName2, jointTypeCode1, jointTypeName1, jointTypeCode2, jointTypeName2, seq, _WELDLOG_DETAIL_ID)
            If returnExecute = True Then
                MsgBox("Update Successfully.", MsgBoxStyle.Information, "EQAM")
                txtWeldInputBarcodeO1.Text = ""
                txtWeldInputBarcodeO2.Text = ""
                txtWeldInputBarcodeI.Text = ""
                txtWeldInputBarcodeI.Focus()

            Else
                'MessageBox.Show("Error!")
                Return
            End If
        End If
    End Sub

    Private Sub btnWeldCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWeldCancel.Click
        loadPanel(_FROM_SCREEN_ID)
    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub

    Private Sub cboCreateCouponMaterial_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCreateCouponMaterial.SelectedIndexChanged
        'Dim rdr As SqlCeResultSet

        'rdr = dao.findTubeType(cboCreateCouponMaterial.Text)

        'Me.cboCreateCouponSize.Items.Clear()
        'Me.cboCreateCouponThickness.Items.Clear()
        'While (rdr.Read)
        'cboCreateCouponSize.Items.Add(rdr.GetString(rdr.GetOrdinal("SIZE")))
        'cboCreateCouponThickness.Items.Add(rdr.GetString(rdr.GetOrdinal("THICKNESS")))
        'End While
        'dao.closeConnection()
    End Sub

    Private Sub cboCreateCouponSize_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCreateCouponSize.SelectedIndexChanged
        'Dim rdr As SqlCeResultSet

        'rdr = dao.getThickness(cboCreateCouponSize.Text)

        'If (rdr.Read) Then
        ' cboCreateCouponThickness.Text = rdr.GetString(rdr.GetOrdinal("THICKNESS"))
        'End If
        'dao.closeConnection()
        If (cboCreateCouponSize.Text <> "" And cboCreateCouponJointType1.Text() <> "") Then
            Dim heatNumber As String = dao.fetchHeatNumberByWeldSizeJointType(_PROJECT_ID, cboCreateCouponSize.Text, cboCreateCouponJointType1.Text)
            cboCreateCouponHeat1.Text = heatNumber
        End If
        If (cboCreateCouponSize.Text <> "" And cboCreateCouponJointType2.Text() <> "") Then
            Dim heatNumber As String = dao.fetchHeatNumberByWeldSizeJointType(_PROJECT_ID, cboCreateCouponSize.Text, cboCreateCouponJointType2.Text)
            cboCreateCouponHeat2.Text = heatNumber
        End If
    End Sub

    Private Sub cboCreateCouponThickness_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCreateCouponThickness.SelectedIndexChanged
        'Dim rdr As SqlCeResultSet

        'rdr = dao.getSize(cboCreateCouponThickness.Text)

        'If (rdr.Read) Then
        ' cboCreateCouponSize.Text = rdr.GetString(rdr.GetOrdinal("SIZE"))
        'End If
        'dao.closeConnection()
    End Sub

    Private Sub cboCreateCouponJointType1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCreateCouponJointType1.SelectedIndexChanged
        If (cboCreateCouponSize.Text <> "" And cboCreateCouponJointType1.Text() <> "") Then
            Dim heatNumber As String = dao.fetchHeatNumberByWeldSizeJointType(_PROJECT_ID, cboCreateCouponSize.Text, cboCreateCouponJointType1.Text)
            cboCreateCouponHeat1.Text = heatNumber
        End If
    End Sub

    Private Sub cboCreateCouponJointType2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCreateCouponJointType2.SelectedIndexChanged
        If (cboCreateCouponSize.Text <> "" And cboCreateCouponJointType2.Text() <> "") Then
            Dim heatNumber As String = dao.fetchHeatNumberByWeldSizeJointType(_PROJECT_ID, cboCreateCouponSize.Text, cboCreateCouponJointType2.Text)
            cboCreateCouponHeat2.Text = heatNumber
        End If
    End Sub

    Sub btnStartCoupon_default()
        btnStartCoupon.Enabled = False
        btnStartCoupon.Text = Globals.BUTTON_LABEL_START
    End Sub

    Private Sub btnCouponConfirmApprove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCouponConfirmApprove.Click
        Dim returnExecute As Boolean = False
        Dim rejectReason As String = ""
        Dim statusCode As String = ""

        If (cboCouponConfirmStatus.Text = "Pending") Then
            statusCode = Globals.COUPON_STATUS_PENDING
        ElseIf (cboCouponConfirmStatus.Text = "Approve") Then
            statusCode = Globals.COUPON_STATUS_APPROVED
        ElseIf (cboCouponConfirmStatus.Text = "Reject") Then
            statusCode = Globals.COUPON_STATUS_REJECTED
            rejectReason = cboCouponConfirmReason.Text

            If (rejectReason = "") Then
                MsgBox("Reject Reason is empty.", MsgBoxStyle.Information, "EQAM")
                Return
            End If
        ElseIf (cboCouponConfirmStatus.Text = "Complete") Then
            statusCode = Globals.COUPON_STATUS_COMPLETED
        End If

        returnExecute = dao.updateCouponStatus(txtCouponConfirmRemark.Text, rejectReason, statusCode, lblSelectedCouponId.Text)

        If returnExecute = True Then
            MsgBox(_SAVE_SUCCESSFUL_MESSAGE, MsgBoxStyle.Information, "EQAM")
            loadEngineerCouponScreen()
        Else
            'MessageBox.Show("Error!")
            Return
        End If

    End Sub

    Private Sub btnCouponConfirmReject_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCouponConfirmReject.Click
        Dim returnExecute As Boolean = False

        returnExecute = dao.updateCouponStatus(txtCouponConfirmRemark.Text, cboCouponConfirmReason.Text, Globals.COUPON_STATUS_REJECTED, lblSelectedCouponId.Text)

        If returnExecute = True Then
            MsgBox(_SAVE_SUCCESSFUL_MESSAGE, MsgBoxStyle.Information, "EQAM")
            loadEngineerCouponScreen()
        Else
            'MessageBox.Show("Error!")
            Return
        End If
    End Sub

    Private Sub chkCreateCouponCoax_CheckStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCreateCouponCoax.CheckStateChanged
        If chkCreateCouponCoax.Checked = True Then
            cboCreateCouponCoax.Enabled = True
        Else
            cboCreateCouponCoax.Enabled = False
            'cboCreateCouponCoax.Text = ""
        End If
    End Sub

    Private Sub lvEngineerCouponList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvEngineerCouponList.SelectedIndexChanged
        Dim sic As ListView.SelectedIndexCollection
        sic = lvEngineerCouponList.SelectedIndices()

        If sic.Count <> 0 Then
            Dim statusCode As String = lvEngineerCouponList.Items(sic.Item(0)).SubItems(3).Text
            If (Globals.COUPON_STATUS_APPROVED = statusCode) Then
                btnEngineerCouponApprove.Enabled = True
                btnEngineerCouponEdit.Enabled = True
            ElseIf (Globals.COUPON_STATUS_PENDING = statusCode) Then
                btnEngineerCouponApprove.Enabled = True
                btnEngineerCouponEdit.Enabled = True
                lblSelectedCouponId.Text = lvEngineerCouponList.Items(sic.Item(0)).Tag
            ElseIf (Globals.COUPON_STATUS_COMPLETED = statusCode) Then
                btnEngineerCouponApprove.Enabled = False
                btnEngineerCouponEdit.Enabled = True
            ElseIf (Globals.COUPON_STATUS_REJECTED = statusCode) Then
                btnEngineerCouponApprove.Enabled = True
                btnEngineerCouponEdit.Enabled = True
            End If
        End If

        'btnEngineerCouponApprove.Enabled = True
        'btnEngineerCouponEdit.Enabled = True
    End Sub
    Private Sub btnEngineerCouponApprove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEngineerCouponApprove.Click
        pnlCouponConfirm.Visible = True
        btnEngineerCouponApprove.Enabled = False
        btnEngineerCouponEdit.Enabled = False        

        pnlCouponConfirm.Location = New System.Drawing.Point(6, 37)
        pnlCouponConfirm.Size = New System.Drawing.Size(216, 293)

        Dim sic As ListView.SelectedIndexCollection
        sic = lvEngineerCouponList.SelectedIndices()

        cboCouponConfirmStatus.Text = "Approve"
        txtCouponConfirmRemark.Text = ""
        cboCouponConfirmReason.Enabled = False

        If sic.Count <> 0 Then
            Dim coupon As String = lvEngineerCouponList.Items(sic.Item(0)).SubItems(0).Text
            Dim typeData As String = lvEngineerCouponList.Items(sic.Item(0)).SubItems(2).Text
            Dim reason As String = lvEngineerCouponList.Items(sic.Item(0)).SubItems(7).Text
            Dim ar As String = lvEngineerCouponList.Items(sic.Item(0)).SubItems(3).Text
            Dim remark As String = lvEngineerCouponList.Items(sic.Item(0)).SubItems(8).Text

            If (ar = vbNullString) Then
                ar = Globals.COUPON_STATUS_APPROVED
            End If

            cboCouponConfirmReason.Text = reason
            cboCouponConfirmStatus.Text = ar
            txtCouponConfirmRemark.Text = remark

            If (ar = Globals.COUPON_STATUS_REJECTED) Then
                cboCouponConfirmReason.Enabled = True
            Else
                cboCouponConfirmReason.Enabled = False
            End If

            lblSelectedCouponId.Text = lvEngineerCouponList.Items(sic.Item(0)).Tag
            txtCouponConfirmCoupon.Text = coupon
            txtCouponConfirmTypeData.Text = typeData
        End If
        'txtCouponConfirmBarcode.Text = ""
        'txtCouponConfirmReason.Text = ""        
        'cboCouponConfirmReason.Text = ""
    End Sub
    Private Sub btnCouponConfirmClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCouponConfirmClose.Click
        pnlCouponConfirm.Visible = False
        btnEngineerCouponApprove.Enabled = True
        btnEngineerCouponEdit.Enabled = True
    End Sub

    Private Sub btnEngineerCouponSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEngineerCouponSearch.Click
        Dim status As String = ""
        If (cboEngineerCouponStatus.Text = "Pending") Then
            status = Globals.COUPON_STATUS_PENDING
        ElseIf (cboEngineerCouponStatus.Text = "Approve") Then
            status = Globals.COUPON_STATUS_APPROVED
        ElseIf (cboEngineerCouponStatus.Text = "Reject") Then
            status = Globals.COUPON_STATUS_REJECTED
        ElseIf (cboEngineerCouponStatus.Text = "Complete") Then
            status = Globals.COUPON_STATUS_COMPLETED
        End If
        searchCoupon(cboEngineerCouponDate.Text, cboEngineerCouponNo.Text, status, txtEngineerCouponBarcode.Text, cboEngineerCouponIO.Text, lvEngineerCouponList)
    End Sub

    Private Sub btnEngineerCouponEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEngineerCouponEdit.Click
        Dim sic As ListView.SelectedIndexCollection
        sic = lvEngineerCouponList.SelectedIndices()
        Dim selectedCouponId As String = ""

        If sic.Count <> 0 Then
            selectedCouponId = lvEngineerCouponList.Items(sic.Item(0)).Tag
            _ACTION = Globals.BUTTON_LABEL_EDIT
            editCoupon(selectedCouponId)
        End If
    End Sub

    Sub startCouponInput(ByVal couponId As String)
        Dim rdr As SqlCeResultSet = dao.findEqamEngineerCouponLists(_PROJECT_ID, vbNullString, vbNullString, vbNullString, couponId, vbNullString, vbNullString)
        If (rdr.Read) Then
            _COUPON_ID = couponId

            '_FROM_SCREEN_ID = _SCREEN_ID
            '_SCREEN_ID = "pnlCreateCoupon"

            If (_ACTION = Globals.BUTTON_LABEL_START) Then
                btnSaveCoupon.Text = Globals.BUTTON_LABEL_CONFIRM
                txtWeldInputBarcodeO1.Text = ""
                txtWeldInputBarcodeO2.Text = ""
                txtWeldInputBarcodeI.Text = ""
                chkWeldInputCouponOut.Checked = False
            ElseIf (_ACTION = Globals.BUTTON_LABEL_EDIT) Then
                btnSaveCoupon.Text = Globals.BUTTON_LABEL_UPDATE
            End If

            Dim tubeType As String = rdr.GetString(rdr.GetOrdinal("MATERIAL")) & "-" & rdr.GetString(rdr.GetOrdinal("SIZE")) & "-" & rdr.GetString(rdr.GetOrdinal("THICKNESS"))
            lblWeldInputMaterial.Text = rdr.GetString(rdr.GetOrdinal("MATERIAL"))
            lblWeldInputSize.Text = rdr.GetString(rdr.GetOrdinal("SIZE"))
            lblWeldInputThickness.Text = rdr.GetString(rdr.GetOrdinal("THICKNESS"))

            Dim pipeTube As String = rdr.GetString(rdr.GetOrdinal("PIPE_TUBE"))
            lblWeldInputPT.Text = pipeTube
            If pipeTube = "PIPE" Then
                tubeType = tubeType & " (PIPE)"
            ElseIf pipeTube = "TUBE" Then
                tubeType = tubeType & " (TUBE)"
            End If

            Dim isCoax As String = rdr.GetString(rdr.GetOrdinal("IS_COAX"))
            lblWeldInputIsCoax.Text = isCoax
            If (isCoax = "T") Then
                Dim coaxString As String = rdr.GetString(rdr.GetOrdinal("COAX"))
                tubeType = tubeType & " " & coaxString
                lblWeldInputCoax.Text = coaxString
                txtWeldInputBarcodeO1.Enabled = True
                txtWeldInputBarcodeO2.Enabled = True
                txtWeldInputBarcodeI.Enabled = True

                lblWeldInputBarcode1.Text = "Barcode (I)"

                If (coaxString = "Inner") Then
                    pnlWeldInputEx.Location = New System.Drawing.Point(1, 29)
                Else
                    pnlWeldInputEx.Location = New System.Drawing.Point(1, 70)
                End If
            Else
                lblWeldInputCoax.Text = ""
                txtWeldInputBarcodeO1.Enabled = False
                txtWeldInputBarcodeO2.Enabled = False
                txtWeldInputBarcodeI.Enabled = True

                lblWeldInputBarcode1.Text = "Barcode"

                pnlWeldInputEx.Location = New System.Drawing.Point(1, 29)
            End If

            txtWeldInputTubeType.Text = tubeType
            _COUPON_CODE = rdr.GetString(rdr.GetOrdinal("COUPON_CODE"))
            _COUPON_TYPE = rdr.GetString(rdr.GetOrdinal("COUPON_TYPE"))

            cboWeldInputHeat1.Text = rdr.GetString(rdr.GetOrdinal("HEAT_NUMBER_NAME_1"))
            cboWeldInputHeat2.Text = rdr.GetString(rdr.GetOrdinal("HEAT_NUMBER_NAME_2"))
            cboWeldInputJointType1.Text = rdr.GetString(rdr.GetOrdinal("JOINT_TYPE_NAME_1"))
            cboWeldInputJointType2.Text = rdr.GetString(rdr.GetOrdinal("JOINT_TYPE_NAME_2"))

            loadPanel("pnlWeldInput")
        Else
            MsgBox("Invalid Action (ERR002)", MsgBoxStyle.Exclamation, "EQAM")
        End If
        dao.closeConnection()
    End Sub
    Sub editCoupon(ByVal couponId As String)
        Dim rdr As SqlCeResultSet = dao.findEqamEngineerCouponLists(_PROJECT_ID, vbNullString, vbNullString, vbNullString, couponId, vbNullString, vbNullString)
        If (rdr.Read) Then
            _COUPON_ID = couponId
            loadPanel("pnlCreateCoupon")
            '_FROM_SCREEN_ID = _SCREEN_ID
            '_SCREEN_ID = "pnlCreateCoupon"

            'pnlCreateCoupon.Location = New System.Drawing.Point(_LOCATION_X, _LOCATION_Y)
            'pnlCreateCoupon.Size = New System.Drawing.Size(_SIZE_WIDTH, _SIZE_HEIGHT)
            'pnlCreateCoupon.Show()
            loadSizeForCbo(_PROJECT_ID, cboWeldARSize, Nothing)

            If (Globals.USER_ROLE_WELDER = _USER_ROLE) Then
                loadWeldSizeForCbo(_USER_ID, cboCreateCouponSize)
            ElseIf (Globals.USER_ROLE_ENGINEER = _USER_ROLE) Then
                cboCreateCouponSize.DropDownStyle = ComboBoxStyle.DropDown
            End If

            loadThicknessForCbo(_PROJECT_ID, cboWeldARThickness, cboCreateCouponThickness)

            'loadMaterialForCbo(cboCreateCouponMaterial)
            txtCreateCouponNo.Text = rdr.GetString(rdr.GetOrdinal("COUPON_CODE"))
            cboCreateCouponCoax.Text = rdr.GetString(rdr.GetOrdinal("COAX"))
            cboCreateCouponMaterial.Text = rdr.GetString(rdr.GetOrdinal("MATERIAL"))
            cboCreateCouponSize.Text = rdr.GetString(rdr.GetOrdinal("SIZE"))
            cboCreateCouponThickness.Text = rdr.GetString(rdr.GetOrdinal("THICKNESS"))
            cboCreateCouponHeat1.Text = rdr.GetString(rdr.GetOrdinal("HEAT_NUMBER_NAME_1"))
            cboCreateCouponHeat2.Text = rdr.GetString(rdr.GetOrdinal("HEAT_NUMBER_NAME_2"))
            cboCreateCouponJointType1.Text = rdr.GetString(rdr.GetOrdinal("JOINT_TYPE_NAME_1"))
            cboCreateCouponJointType2.Text = rdr.GetString(rdr.GetOrdinal("JOINT_TYPE_NAME_2"))
            txtCreateCouponBarcode.Text = rdr.GetString(rdr.GetOrdinal("BARCODE"))

            If (_ACTION = Globals.BUTTON_LABEL_EDIT) Then
                btnSaveCoupon.Text = Globals.BUTTON_LABEL_UPDATE
            ElseIf (_ACTION = Globals.BUTTON_LABEL_REDO) Then
                btnSaveCoupon.Text = Globals.BUTTON_LABEL_REDO
                txtCreateCouponBarcode.Text = ""
            End If

            Dim pipeTube As String = rdr.GetString(rdr.GetOrdinal("PIPE_TUBE"))
            Dim isCoax As String = rdr.GetString(rdr.GetOrdinal("IS_COAX"))

            If (isCoax = "T") Then
                chkCreateCouponCoax.Checked = True
            Else
                chkCreateCouponCoax.Checked = False
            End If

            If pipeTube = "PIPE" Then
                rdoCreateCouponPipe.Checked = True
            ElseIf pipeTube = "TUBE" Then
                rdoCreateCouponTube.Checked = True
            End If

            rdr = dao.findCouponSystems(couponId)
            Dim lstItem As ListViewItem
            'uncheck all items
            For Each lstItem In lvCouponSystemType.Items
                lstItem.Checked = False
            Next

            While (rdr.Read)
                For Each lstItem In lvCouponSystemType.Items
                    If (lstItem.Tag = rdr.GetString(rdr.GetOrdinal("SYSTEM_TYPE_ID"))) Then
                        lstItem.Checked = True
                        Exit For
                    Else
                        'lstItem.Checked = False
                    End If
                Next

            End While
        Else
            MsgBox("Invalid Action (ERR001)", MsgBoxStyle.Exclamation, "EQAM")
        End If
        dao.closeConnection()
    End Sub

    Private Sub lvCoupon_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvCoupon.SelectedIndexChanged
        Dim sic As ListView.SelectedIndexCollection
        sic = lvCoupon.SelectedIndices()

        btnStartCoupon_default()

        If sic.Count <> 0 Then
            Dim statusCode As String = lvCoupon.Items(sic.Item(0)).SubItems(3).Text
            If (Globals.COUPON_STATUS_APPROVED = statusCode Or Globals.COUPON_STATUS_COMPLETED = statusCode) Then
                btnStartCoupon.Enabled = True
                btnStartCoupon.Text = Globals.BUTTON_LABEL_START
            ElseIf (Globals.COUPON_STATUS_PENDING = statusCode) Then
                btnStartCoupon.Enabled = True
                btnStartCoupon.Text = Globals.BUTTON_LABEL_EDIT
            ElseIf (Globals.COUPON_STATUS_REJECTED = statusCode) Then
                btnStartCoupon.Enabled = True
                btnStartCoupon.Text = Globals.BUTTON_LABEL_REDO
            End If
        End If
    End Sub

    Private Sub btnWeldingSequence_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWeldingSequence.Click
        loadPanel("pnlWeldingSeq")
    End Sub

    Private Sub btnAcceptReject_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAcceptReject.Click
        loadPanel("pnlWeldAR")
    End Sub

    Private Sub Tab2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tabWeldInput.SelectedIndexChanged
        If (Me.tabWeldInput.SelectedIndex = 1) Then
            refreshLvWeldInput()
            Me.tabWeldInput.Refresh()
        End If
    End Sub

    Sub refreshLvWeldInput()
        Dim rdr As SqlCeResultSet
        Dim lstView As New ListViewItem

        rdr = dao.findWeldLogs(_COUPON_CODE, Nothing, Nothing, Nothing, Nothing, Globals.COUPON_TYPE_IN, False, Nothing)

        Me.lvWeldInput.Items.Clear()
        While (rdr.Read)
            lstView = Me.lvWeldInput.Items.Add(New ListViewItem(rdr.GetDecimal(rdr.GetOrdinal("SEQ"))))
            lstView.SubItems.Add(rdr.GetString(rdr.GetOrdinal("SYSTEM_TYPE_NAME")))
            lstView.SubItems.Add(rdr.GetString(rdr.GetOrdinal("HEAT_NUMBER_NAME_1")) & "-" & rdr.GetString(rdr.GetOrdinal("HEAT_NUMBER_NAME_2")))
            lstView.SubItems.Add(rdr.GetString(rdr.GetOrdinal("JOINT_TYPE_NAME_1")) & "-" & rdr.GetString(rdr.GetOrdinal("JOINT_TYPE_NAME_2")))
            'lstView.SubItems.Add(rdr.GetString(rdr.GetOrdinal("MATERIAL")) & "-" & rdr.GetString(rdr.GetOrdinal("SIZE")) & "-" & rdr.GetString(rdr.GetOrdinal("THICKNESS")))
            lstView.SubItems.Add(rdr.GetString(rdr.GetOrdinal("BARCODE_OUT_1")))
            lstView.SubItems.Add(rdr.GetString(rdr.GetOrdinal("BARCODE_OUT_2")))
            lstView.SubItems.Add(rdr.GetString(rdr.GetOrdinal("BARCODE_IN_1")))
            lstView.Tag = rdr.GetInt64(rdr.GetOrdinal("WELDLOG_DETAIL_ID"))
        End While
        dao.closeConnection()
    End Sub

    Private Sub TabControl2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tabWeldAR.SelectedIndexChanged
        If (Me.tabWeldAR.SelectedIndex = 1) Then
            'loadWeldInputData()
            Me.tabWeldAR.Refresh()
        End If
    End Sub

    Private Sub txtWeldARBarcode_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtWeldARBarcode.KeyPress
        If Asc(e.KeyChar) = Keys.Enter Then
            'MessageBox.Show("Enter")
            Dim barcode As String = txtWeldARBarcode.Text
            clearPnlWeldAR()
            searchWeldlogDetailForAR(barcode)
        End If
    End Sub

    Sub searchWeldlogDetailForAR(ByVal barcode As String)
        Dim rdr As SqlCeResultSet
        Dim lstView As New ListViewItem

        rdr = dao.findWeldLogs(Nothing, barcode, Nothing, Nothing, Nothing, Globals.COUPON_TYPE_IN, False, Nothing)
        txtWeldARBarcode.Text = barcode

        If (rdr.Read) Then
            txtWeldARWelder.Text = rdr.GetString(rdr.GetOrdinal("WELDER_NAME"))
            txtWeldARCoupon.Text = rdr.GetString(rdr.GetOrdinal("COUPON_CODE"))
            txtWeldARDate.Text = rdr.GetDecimal(rdr.GetOrdinal("WELD_DATE")) & " " & rdr.GetDecimal(rdr.GetOrdinal("WELD_TIME"))

            Dim isCoas As String = ""
            Dim coax As String = ""

            txtWeldARSeq.Text = rdr.GetDecimal(rdr.GetOrdinal("SEQ"))

            Dim pipeTube As String = rdr.GetString(rdr.GetOrdinal("PIPE_TUBE"))
            Dim isCoax As String = rdr.GetString(rdr.GetOrdinal("IS_COAX"))

            If (isCoax = "T") Then
                cbWeldARCoax.Checked = True
            Else
                cbWeldARCoax.Checked = False
            End If

            If pipeTube = "PIPE" Then
                rdoWeldARPipe.Checked = True
            ElseIf pipeTube = "TUBE" Then
                rdoWeldARTube.Checked = True
            End If

            cboWeldARCoax.Text = rdr.GetString(rdr.GetOrdinal("COAX"))
            cboWeldARMaterial.Text = rdr.GetString(rdr.GetOrdinal("MATERIAL"))
            cboWeldARSize.Text = rdr.GetString(rdr.GetOrdinal("SIZE"))
            cboWeldARThickness.Text = rdr.GetString(rdr.GetOrdinal("THICKNESS"))
            cboWeldARSystem.Text = rdr.GetString(rdr.GetOrdinal("SYSTEM_TYPE_NAME"))
            cboWeldARHeat1.Text = rdr.GetString(rdr.GetOrdinal("HEAT_NUMBER_NAME_1"))
            cboWeldARHeat2.Text = rdr.GetString(rdr.GetOrdinal("HEAT_NUMBER_NAME_2"))
            cboWeldARJointType1.Text = rdr.GetString(rdr.GetOrdinal("JOINT_TYPE_NAME_1"))
            cboWeldARJointType2.Text = rdr.GetString(rdr.GetOrdinal("JOINT_TYPE_NAME_2"))
            txtWeldARStatus.Text = rdr.GetString(rdr.GetOrdinal("STATUS_CODE"))

            btnWeldAccept.Enabled = True
            btnWeldReject.Enabled = True

            lblARWeldLogDetailId.Text = rdr.GetInt64(rdr.GetOrdinal("WELDLOG_DETAIL_ID"))
        Else
            MsgBox("Barcode not found.", MsgBoxStyle.Information, "EQAM")
            clearPnlWeldAR()

            btnWeldAccept.Enabled = False
            btnWeldReject.Enabled = False
        End If
        dao.closeConnection()
    End Sub

    Private Sub chkWeldInputCouponOut_CheckStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkWeldInputCouponOut.CheckStateChanged
        If (chkWeldInputCouponOut.Checked = True) Then        
            chkWeldInputReplaceWeld.Checked = False
            lblWeldInputBarcode2.Visible = False
            lblWeldInputBarcode3.Visible = False
            txtWeldInputBarcodeO1.Visible = False
            txtWeldInputBarcodeO2.Visible = False
        Else
            lblWeldInputBarcode2.Visible = True
            lblWeldInputBarcode3.Visible = True
            txtWeldInputBarcodeO1.Visible = True
            txtWeldInputBarcodeO2.Visible = True
        End If
    End Sub

    Private Sub chkWeldInputReplaceWeld_CheckStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkWeldInputReplaceWeld.CheckStateChanged
        If (chkWeldInputReplaceWeld.Checked = True) Then
            chkWeldInputCouponOut.Checked = False
        Else
            chkWeldInputReplaceWeld.Visible = False
        End If
    End Sub

    Private Sub btnReplaceRejectedWeld_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReplaceRejectedWeld.Click
        loadPanel("pnlReplaceWeld")
    End Sub

    Private Sub MenuItemReplaceWeld_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemReplaceWeld.Click
        loadPanel("pnlReplaceWeld")
    End Sub

    Private Sub MenuItemWeldSeq_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemWeldSeq.Click
        loadPanel("pnlWeldingSeq")
    End Sub

    Private Sub btnReplaceWeldReplace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReplaceWeldReplace.Click
        pnlReplaceWeldEx.Visible = True
        btnReplaceWeldReplace.Enabled = False

        pnlReplaceWeldEx.Location = New System.Drawing.Point(13, 28)
        pnlReplaceWeldEx.Size = New System.Drawing.Size(218, 265)

        '''''''''''''''
        Dim sic As ListView.SelectedIndexCollection

        sic = lvReplaceWeld.SelectedIndices()
        If sic.Count <> 0 Then
            Dim weldLogId As String = lvReplaceWeld.Items(sic.Item(0)).Tag
            Dim barcode As String = lvReplaceWeld.Items(sic.Item(0)).SubItems(2).Text
            Dim coax As String = lvReplaceWeld.Items(sic.Item(0)).SubItems(6).Text

            lblRejectedWeldO1.Visible = False
            lblRejectedWeldO2.Visible = False
            txtRejectedWeldBarcodeO1.Visible = False
            txtRejectedWeldBarcodeO2.Visible = False

            'txtRejectedWeldBarcodeO1.Text = barcode
            lblRejectedWeldId.Text = weldLogId

            If (coax IsNot "") Then
                If (coax = "Outer") Then
                    lblRejectedWeldO1.Visible = True
                    lblRejectedWeldO2.Visible = True
                    txtRejectedWeldBarcodeO1.Visible = True
                    txtRejectedWeldBarcodeO2.Visible = True
                End If
            End If
        End If
    End Sub

    Private Sub btnReplaceWeldClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReplaceWeldClose.Click
        pnlReplaceWeldEx.Visible = False
        btnReplaceWeldReplace.Enabled = True
    End Sub

    Private Sub btnReplaceWeldSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReplaceWeldSave.Click
        pnlReplaceWeldEx.Visible = False
        btnReplaceWeldReplace.Enabled = True

        If (txtRejectedWeld.Text = "") Then
            MsgBox("Rejected Weld No. cannot be blank.", MsgBoxStyle.Information, "EQAM")
            Return
        End If
        If (txtRejectedWeldBarcodeI.Text = "") Then
            MsgBox("Barcode (In) cannot be blank.", MsgBoxStyle.Information, "EQAM")
            Return
        End If
        If (txtRejectedWeldBarcodeO1.Text = "" And txtRejectedWeldBarcodeO1.Visible = True) Then
            MsgBox("Barcode (Out) cannot be blank.", MsgBoxStyle.Information, "EQAM")
            Return
        End If
        If (txtRejectedWeldBarcodeO2.Text = "" And txtRejectedWeldBarcodeO2.Visible = True) Then
            MsgBox("Barcode (Out) cannot be blank.", MsgBoxStyle.Information, "EQAM")
            Return
        End If
        dao.saveRejectedWeldNo(_PROJECT_ID, lblRejectedWeldId.Text, txtRejectedWeld.Text, txtRejectedWeldBarcodeI.Text, txtRejectedWeldBarcodeO1.Text, txtRejectedWeldBarcodeO2.Text)
        MsgBox("Replace Weld Successfully.", MsgBoxStyle.Information, "E-QAM")
        loadRejectWeld()

        pnlReplaceWeldEx.Visible = False
        btnReplaceWeldReplace.Enabled = True
    End Sub

    Private Sub btnWeldInputDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWeldInputDelete.Click
        Dim list As New ArrayList

        ' save coupon system
        Dim lstItem As ListViewItem
        For Each lstItem In lvWeldInput.Items
            If (lstItem.Checked) Then
                Dim seqId As String = lstItem.Tag
                list.Add(seqId)
            End If
        Next

        dao.deleteWeldLog(list)

        refreshLvWeldInput()
    End Sub

    Private Sub btnWeldInputEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWeldInputEdit.Click
        Dim sic As ListView.SelectedIndexCollection
        sic = lvWeldInput.SelectedIndices()
        Dim selectedWeldId As String = ""

        If sic.Count <> 0 Then
            selectedWeldId = lvWeldInput.Items(sic.Item(0)).Tag

            btnWeldConfirm.Text = BUTTON_LABEL_UPDATE
            _ACTION = Globals.BUTTON_LABEL_EDIT
            editWeldLog(selectedWeldId)
        End If
    End Sub

    Private Sub btnWeldingSeqSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWeldingSeqSave.Click
        Dim returnExecute As Boolean = False
        If (cboWeldingSeqZone.Text = "") Then
            MsgBox("Zone cannot be blank.", MsgBoxStyle.Information, "EQAM")
            Return
        End If
        If (txtWeldingSeqBarcode.Text = "") Then
            MsgBox("Barcode cannot be blank.", MsgBoxStyle.Information, "EQAM")
            Return
        End If
        If (txtWeldingSeqNo.Text = "") Then
            MsgBox("Seq No. cannot be blank", MsgBoxStyle.Information, "EQAM")
            Return
        End If

        returnExecute = dao.saveWeldSeq(_PROJECT_ID, cboWeldingSeqZone.Text, txtWeldingSeqBarcode.Text, txtWeldingSeqNo.Text)
        If returnExecute = True Then
            MsgBox("Save Successfully.", MsgBoxStyle.Information, "EQAM")
            txtWeldingSeqNo.Text = dao.getZoneSeq(cboWeldingSeqZone.Text, _PROJECT_ID)
            txtWeldingSeqBarcode.Text = ""
            txtWeldingSeqBarcode.Focus()
        Else
            'MessageBox.Show("Error!")
            Return
        End If
    End Sub

    Private Sub btnCouponSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCouponSearch.Click
        welderFindCoupon()
    End Sub

    Sub welderFindCoupon()
        Dim status As String = ""
        If (cboCouponStatus.Text = "Pending") Then
            status = Globals.COUPON_STATUS_PENDING
        ElseIf (cboCouponStatus.Text = "Approve") Then
            status = Globals.COUPON_STATUS_APPROVED
        ElseIf (cboCouponStatus.Text = "Reject") Then
            status = Globals.COUPON_STATUS_REJECTED
        ElseIf (cboCouponStatus.Text = "Complete") Then
            status = Globals.COUPON_STATUS_COMPLETED
        End If
        searchCoupon(cboCouponDate.Text, cboCouponNo.Text, status, txtCouponBarcode.Text, cboCouponInOut.Text, lvCoupon)
    End Sub

    Private Sub btnWeldAREdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWeldAREdit.Click
        ' todo
    End Sub

    Private Sub btnWeldARDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWeldARDelete.Click
        ' todo
    End Sub

    Private Sub cboCouponConfirmStatus_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCouponConfirmStatus.SelectedIndexChanged
        If ("Reject" = cboCouponConfirmStatus.Text) Then
            cboCouponConfirmReason.Enabled = True
        Else
            cboCouponConfirmReason.Enabled = False
            cboCouponConfirmReason.Text = ""
        End If
    End Sub

    Private Sub cboWeldingSeqZone_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboWeldingSeqZone.SelectedIndexChanged
        If (cboWeldingSeqZone.Text IsNot "") Then
            txtWeldingSeqNo.Text = dao.getZoneSeq(cboWeldingSeqZone.Text, _PROJECT_ID)
        Else
            txtWeldingSeqNo.Text = 1
        End If
    End Sub

    Private Sub tabZoneSeq_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tabZoneSeq.SelectedIndexChanged
        If (Me.tabZoneSeq.SelectedIndex = 1) Then
            refreshLvWeldingSeq()
            Me.tabZoneSeq.Refresh()
        End If
    End Sub

    Private Sub cboWeldingSeqZoneFilter_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboWeldingSeqZoneFilter.SelectedIndexChanged
        refreshLvWeldingSeq()
    End Sub

    Sub refreshLvWeldingSeq()
        Dim rdr As SqlCeResultSet
        Dim lstView As New ListViewItem

        Me.lvWeldingSeq.Items.Clear()
        If (cboWeldingSeqZoneFilter.Text <> "") Then
            rdr = dao.findWeldSeq(_PROJECT_ID, cboWeldingSeqZoneFilter.Text)

            While (rdr.Read)
                lstView = Me.lvWeldingSeq.Items.Add(New ListViewItem(rdr.GetDecimal(rdr.GetOrdinal("SEQ"))))
                lstView.SubItems.Add(rdr.GetString(rdr.GetOrdinal("BARCODE")))
                lstView.SubItems.Add(rdr.GetString(rdr.GetOrdinal("ZONE")))

                lstView.Tag = rdr.GetInt64(rdr.GetOrdinal("SEQ_ID"))
            End While
            dao.closeConnection()
        End If
    End Sub

    Private Sub btnWeldingSeqDeleteAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWeldingSeqDeleteAll.Click
        dao.deleteWeldSeq(_PROJECT_ID, cboWeldingSeqZoneFilter.Text, Nothing)
        refreshLvWeldingSeq()
    End Sub

    Private Sub btnWeldingSeqDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWeldingSeqDelete.Click
        Dim list As New ArrayList

        ' save coupon system
        Dim lstItem As ListViewItem
        For Each lstItem In lvWeldingSeq.Items
            If (lstItem.Checked) Then
                Dim seqId As String = lstItem.Tag
                list.Add(seqId)
            End If
        Next

        dao.deleteWeldSeq(_PROJECT_ID, cboWeldingSeqZoneFilter.Text, list)

        refreshLvWeldingSeq()
    End Sub

    Private Sub btnReplaceWeldSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReplaceWeldSearch.Click
        loadRejectWeld()
    End Sub

    Private Sub btnWeldARSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWeldARSearch.Click
        ' todo
    End Sub

    Sub loadRejectWeld()
        Dim rdr As SqlCeResultSet
        Dim lstView As New ListViewItem
        Dim barcode As String = txtReplaceWeldBarcode.Text
        Dim coupon As String = cboReplaceWeldCoupon.Text
        Dim weldInputDate As String = cboReplaceWeldDate.Text

        rdr = dao.findWeldLogs(coupon, barcode, weldInputDate, WELDLOG_STATUS_REJECTED, Nothing, Globals.COUPON_TYPE_IN, True, _USER_ID)

        Me.lvReplaceWeld.Items.Clear()
        While (rdr.Read)
            lstView = Me.lvReplaceWeld.Items.Add(New ListViewItem(rdr.GetString(rdr.GetOrdinal("COUPON_CODE"))))
            lstView.SubItems.Add(rdr.GetDecimal(rdr.GetOrdinal("SEQ")))
            Dim couponCode As String = ""

            If (rdr.IsDBNull(rdr.GetOrdinal("BARCODE_OUT_1")) = False) Then
                couponCode = rdr.GetString(rdr.GetOrdinal("BARCODE_OUT_1"))
            End If
            If (rdr.IsDBNull(rdr.GetOrdinal("BARCODE_OUT_2")) = False) Then
                If (couponCode <> "") Then
                    couponCode = couponCode & "/" & rdr.GetString(rdr.GetOrdinal("BARCODE_OUT_2"))
                Else
                    couponCode = rdr.GetString(rdr.GetOrdinal("BARCODE_OUT_2"))
                End If
            End If
            If (rdr.IsDBNull(rdr.GetOrdinal("BARCODE_IN_1")) = False) Then
                If (couponCode <> "") Then
                    couponCode = couponCode & "/" & rdr.GetString(rdr.GetOrdinal("BARCODE_IN_1"))
                Else
                    couponCode = rdr.GetString(rdr.GetOrdinal("BARCODE_IN_1"))
                End If

            End If
            lstView.SubItems.Add(couponCode)
            lstView.SubItems.Add(rdr.GetString(rdr.GetOrdinal("MATERIAL")) & "-" & rdr.GetString(rdr.GetOrdinal("SIZE")) & "-" & rdr.GetString(rdr.GetOrdinal("THICKNESS")))
            lstView.SubItems.Add(rdr.GetDecimal(rdr.GetOrdinal("WELD_DATE")) & "-" & rdr.GetDecimal(rdr.GetOrdinal("WELD_TIME")))
            lstView.SubItems.Add(rdr.GetString(rdr.GetOrdinal("SYSTEM_TYPE_NAME")))
            lstView.SubItems.Add(rdr.GetString(rdr.GetOrdinal("COAX")))
            lstView.SubItems.Add(rdr.GetString(rdr.GetOrdinal("REJECT_REASON")))
            lstView.Tag = rdr.GetInt64(rdr.GetOrdinal("WELDLOG_DETAIL_ID"))
        End While
        dao.closeConnection()
    End Sub

    Private Sub tabWeldInput_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tabWeldInput.SelectedIndexChanged
        If (Me.tabWeldInput.SelectedIndex = 1) Then
            refreshLvWeldInput()
            Me.tabWeldInput.Refresh()
        End If
    End Sub

    Sub editWeldLog(ByVal weldId As String)
        Dim rdr As SqlCeResultSet = dao.findWeldLogs(vbNullString, vbNullString, vbNullString, vbNullString, weldId, Globals.COUPON_TYPE_IN, False, Nothing)
        If (rdr.Read) Then
            _WELDLOG_DETAIL_ID = weldId

            Dim tubeType As String = rdr.GetString(rdr.GetOrdinal("MATERIAL")) & "-" & rdr.GetString(rdr.GetOrdinal("SIZE")) & "-" & rdr.GetString(rdr.GetOrdinal("THICKNESS"))
            lblWeldInputMaterial.Text = rdr.GetString(rdr.GetOrdinal("MATERIAL"))
            lblWeldInputSize.Text = rdr.GetString(rdr.GetOrdinal("SIZE"))
            lblWeldInputThickness.Text = rdr.GetString(rdr.GetOrdinal("THICKNESS"))
            txtWeldInputSeq.Text = rdr.GetDecimal(rdr.GetOrdinal("SEQ"))

            Dim pipeTube As String = rdr.GetString(rdr.GetOrdinal("PIPE_TUBE"))
            lblWeldInputPT.Text = pipeTube
            If pipeTube = "PIPE" Then
                tubeType = tubeType & " (PIPE)"
            ElseIf pipeTube = "TUBE" Then
                tubeType = tubeType & " (TUBE)"
            End If

            Dim isCoax As String = rdr.GetString(rdr.GetOrdinal("IS_COAX"))
            lblWeldInputIsCoax.Text = isCoax
            If (isCoax = "T") Then
                Dim coaxString As String = rdr.GetString(rdr.GetOrdinal("COAX"))
                tubeType = tubeType & " " & coaxString
                lblWeldInputCoax.Text = coaxString
                txtWeldInputBarcodeO1.Enabled = True
                txtWeldInputBarcodeO2.Enabled = True
                txtWeldInputBarcodeI.Enabled = True

                lblWeldInputBarcode1.Text = "Barcode (I)"

                If (coaxString = "Inner") Then
                    pnlWeldInputEx.Location = New System.Drawing.Point(1, 29)
                Else
                    pnlWeldInputEx.Location = New System.Drawing.Point(1, 70)
                End If
            Else
                lblWeldInputCoax.Text = ""
                txtWeldInputBarcodeO1.Enabled = False
                txtWeldInputBarcodeO2.Enabled = False
                txtWeldInputBarcodeI.Enabled = True

                lblWeldInputBarcode1.Text = "Barcode"

                pnlWeldInputEx.Location = New System.Drawing.Point(1, 29)
            End If

            txtWeldInputTubeType.Text = tubeType
            _COUPON_CODE = rdr.GetString(rdr.GetOrdinal("COUPON_CODE"))
            _COUPON_TYPE = rdr.GetString(rdr.GetOrdinal("COUPON_TYPE"))

            cboWeldInputHeat1.Text = rdr.GetString(rdr.GetOrdinal("HEAT_NUMBER_NAME_1"))
            cboWeldInputHeat2.Text = rdr.GetString(rdr.GetOrdinal("HEAT_NUMBER_NAME_2"))
            cboWeldInputJointType1.Text = rdr.GetString(rdr.GetOrdinal("JOINT_TYPE_NAME_1"))
            cboWeldInputJointType2.Text = rdr.GetString(rdr.GetOrdinal("JOINT_TYPE_NAME_2"))
        Else
            MsgBox("Invalid Action (ERR003)", MsgBoxStyle.Exclamation, "EQAM")
        End If
        dao.closeConnection()
    End Sub

    Private Sub btnWeldAccept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWeldAccept.Click
        Dim returnExecute As Boolean = False
        Dim rejectReason As String = ""
        Dim statusCode As String = ""

        statusCode = Globals.WELDLOG_STATUS_ACCEPT
        rejectReason = ""
        'rejectReason = cboWeldARRejectReason.Text

        'If (rejectReason = "") Then
        'MsgBox("Reject Reason is empty.", MsgBoxStyle.Information, "EQAM")
        'Return
        'End If

        returnExecute = dao.updateWeldStatus("", rejectReason, statusCode, lblARWeldLogDetailId.Text)

        If returnExecute = True Then
            MsgBox(_SAVE_SUCCESSFUL_MESSAGE, MsgBoxStyle.Information, "EQAM")
            clearPnlWeldAR()
        Else
            'MessageBox.Show("Error!")
            Return
        End If
    End Sub

    Private Sub btnWeldReject_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWeldReject.Click
        pnlWeldReject.Visible = True
        btnWeldAccept.Enabled = False
        btnWeldReject.Enabled = False

        pnlWeldReject.Location = New System.Drawing.Point(5, 69)
        pnlWeldReject.Size = New System.Drawing.Size(209, 215)
    End Sub

    Private Sub cboWeldARRejectClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboWeldARRejectClose.Click
        pnlWeldReject.Visible = False
        btnWeldAccept.Enabled = True
        btnWeldReject.Enabled = True
    End Sub

    Private Sub btnWeldARRejectSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWeldARRejectSave.Click
        Dim returnExecute As Boolean = False
        Dim rejectReason As String = ""
        Dim statusCode As String = ""

        statusCode = Globals.COUPON_STATUS_REJECTED
        rejectReason = cboWeldARRejectReason.Text

        If (rejectReason = "") Then
            MsgBox("Reject Reason is empty.", MsgBoxStyle.Information, "EQAM")
            Return
        End If

        returnExecute = dao.updateWeldStatus(txtWeldARRejectRemark.Text, rejectReason, statusCode, lblARWeldLogDetailId.Text)

        If returnExecute = True Then
            MsgBox(_SAVE_SUCCESSFUL_MESSAGE, MsgBoxStyle.Information, "EQAM")
            clearPnlWeldAR()
        Else
            'MessageBox.Show("Error!")
            Return
        End If
    End Sub

    Sub clearPnlWeldAR()
        lblARWeldLogDetailId.Text = ""

        pnlWeldReject.Visible = False
        cboWeldARRejectReason.Text = ""
        txtWeldARRejectRemark.Text = ""

        btnWeldAccept.Enabled = True
        btnWeldReject.Enabled = True

        txtWeldARBarcode.Text = ""
        txtWeldARWelder.Text = ""
        txtWeldARCoupon.Text = ""
        txtWeldARDate.Text = ""
        txtWeldARSeq.Text = ""

        cbWeldARCoax.Checked = False
        rdoWeldARPipe.Checked = True

        cboWeldARCoax.Text = ""
        cboWeldARMaterial.Text = ""
        cboWeldARSize.Text = ""
        cboWeldARThickness.Text = ""
        cboWeldARSystem.Text = ""
        cboWeldARHeat1.Text = ""
        cboWeldARHeat2.Text = ""
        cboWeldARJointType1.Text = ""
        cboWeldARJointType2.Text = ""
        txtWeldARStatus.Text = ""
    End Sub

    Private Sub cboWeldInputJointType1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboWeldInputJointType1.SelectedIndexChanged
        If (lblWeldInputSize.Text <> "" And cboWeldInputJointType1.Text() <> "") Then
            Dim heatNumber As String = dao.fetchHeatNumberByWeldSizeJointType(_PROJECT_ID, lblWeldInputSize.Text, cboWeldInputJointType1.Text)
            cboWeldInputHeat1.Text = heatNumber
        End If
    End Sub

    Private Sub cboWeldInputJointType2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboWeldInputJointType2.SelectedIndexChanged
        If (lblWeldInputSize.Text <> "" And cboWeldInputJointType2.Text() <> "") Then
            Dim heatNumber As String = dao.fetchHeatNumberByWeldSizeJointType(_PROJECT_ID, lblWeldInputSize.Text, cboWeldInputJointType2.Text)
            cboWeldInputHeat2.Text = heatNumber
        End If
    End Sub

    Private Sub cboWeldARSize_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboWeldARSize.SelectedIndexChanged
        If (cboWeldARSize.Text <> "" And cboWeldARJointType1.Text() <> "") Then
            Dim heatNumber As String = dao.fetchHeatNumberByWeldSizeJointType(_PROJECT_ID, cboWeldARSize.Text, cboWeldARJointType1.Text)
            cboWeldARHeat1.Text = heatNumber
        End If
        If (cboWeldARSize.Text <> "" And cboWeldARJointType2.Text() <> "") Then
            Dim heatNumber As String = dao.fetchHeatNumberByWeldSizeJointType(_PROJECT_ID, cboWeldARSize.Text, cboWeldARJointType2.Text)
            cboWeldARHeat2.Text = heatNumber
        End If
    End Sub

    Private Sub cboWeldARJointType1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboWeldARJointType1.SelectedIndexChanged
        If (cboWeldARSize.Text <> "" And cboWeldARJointType1.Text() <> "") Then
            Dim heatNumber As String = dao.fetchHeatNumberByWeldSizeJointType(_PROJECT_ID, cboWeldARSize.Text, cboWeldARJointType1.Text)
            cboWeldARHeat1.Text = heatNumber
        End If
    End Sub

    Private Sub cboWeldARJointType2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboWeldARJointType2.SelectedIndexChanged
        If (cboWeldARSize.Text <> "" And cboWeldARJointType2.Text() <> "") Then
            Dim heatNumber As String = dao.fetchHeatNumberByWeldSizeJointType(_PROJECT_ID, cboWeldARSize.Text, cboWeldARJointType2.Text)
            cboWeldARHeat2.Text = heatNumber
        End If
    End Sub


End Class